<!doctype html>
<html lang="en">

<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Hello, world!</title>
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="../css/font-awesome.min.css">
    <link rel="stylesheet" href="../fonts/iconfont.css">
    <link rel="stylesheet" href="../css/bootstrap.min.css">
    <link rel="stylesheet" href="../css/bootstrap-select.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <style>
        .bd-placeholder-img {
            font-size: 1.125rem;
            text-anchor: middle;
            -webkit-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
            user-select: none;
        }

        @media (min-width: 768px) {
            .bd-placeholder-img-lg {
                font-size: 3.5rem;
            }
        }

        html,
        body {
            height: 100%;
        }

        body {
            padding-bottom: 40px;
            background-color: #fff;
        }

        .form-signin {
            width: 100%;
            max-width: 640px;
            margin: auto;
            padding: 15px;
        }
        .table-nest td, .table-nest th{
            padding-left: 2px !important;
            padding-right: 2px !important;
            word-wrap: break-word !important;
            word-break: normal !important;

        }

        .form-signin .checkbox {
            font-weight: 400;
        }

        .form-signin .form-control {
            position: relative;
            box-sizing: border-box;
            height: auto;
            padding: 10px;
            font-size: 16px;
        }
        .wareContent{
            display: flex;
            width: 100%;
            justify-content: center;
            align-items: center;
            position: relative;
        }

        .form-signin .form-control:focus {
            z-index: 2;
        }

        .form-signin input[type="email"] {
            margin-bottom: -1px;
            border-bottom-right-radius: 0;
            border-bottom-left-radius: 0;
        }

        .form-signin input[type="password"] {
            margin-bottom: 10px;
            border-top-left-radius: 0;
            border-top-right-radius: 0;
        }

        .sr-only2 {
            margin-top: 15px;
        }


        .logodiv img {
            width: 240px;
            margin: 0 auto;
            display: block;
        }

        .logodiv {
            text-align: center;
        }

        .logodiv h1 {
            font-size: 1.4rem;
            color: #03357a;
            margin-top: 20px;
            margin-bottom: 20px;
        }

        .logodiv h2 {
            font-size: 1.5rem;
            margin-bottom: 80px;
        }



        .fgtpaws {
            text-align: center;
            margin-top: 10px;
        }

        .btn {
            padding: 0.375rem 0.15rem
        }

        .btn-tiqu {
            width: 125px;
            margin: 0 auto;
            display: block;
        }

        .buytitle {
            font-size: 1.1rem;
            color: #03357a;
            margin-top: 20px;
        }

        .buytitle span {
            font-size: 1rem;
            color: #999;
        }

        .action-row button {
            margin-bottom: 15px;
        }

        .buysearch {
            font-size: smaller;
        }

        .formscreen .form-control-theme {
            font-size: smaller;
        }

        .action-row {
            position: fixed;
            width: 100%;
            bottom: 0;
            margin-top: 0;
            margin-bottom: 0;
            background: #fff;
            left: 0;
        }

        .container2 {
            padding: 10px;
            display: block;
            overflow: hidden;
        }

        .bootstrap-select {
            width: calc(100% - 0px) !important;
        }

        .formscreen .filter-option-inner-inner {
            font-size: smaller;
        }

        .myselect {
            width: calc(100% - 0px);
        }

        .btn-action:disabled {
            background: #D9D9DA !important;
            color: #808081 !important;
        }

        .buysearch {
            width: 100%;
            display: block;
        }
    </style>
</head>

<body>
    <div id="app">
        <div class="container2">



            <div class="modal fade fullmodal show" v-if="screenwidth<576" style="display: block;background: #fff;"
                id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
                <div class="modal-dialog  modal-dialog-scrollable">
                    <div class="modal-content">
                        <div class="modal-body">
                            <div class="logodiv">
                                <img class="bannerlogo pt-3" src="../image/logo.jpeg">
                                <h3 class="mt-3 mb-5">{{lan['Picking_No']}}</h3>
                            </div>
                            <div class="row  align-items-center">

                                <div class="col-12 col-sm-6 col-md-3">
                                    <div class="d-flex bd-highlight align-items-center">
                                        <div class="p-2 bd-highligh  flex-shrink-0 filedlabel">{{lan['Issue_Date']}}
                                        </div>
                                        <div class="p-2 flex-grow-1 bd-highlight">
                                            <input type="date" v-model="searchdata.ArrivedDate"
                                                placeholder="Please Enter Issue Date(Required)"
                                                class="form-control form-control-theme" value="">
                                        </div>
                                    </div>
                                </div>




                                <div class="col-12">
                                    <div class="d-flex bd-highlight align-items-center">
                                        <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['User']}}</div>
                                        <div class="p-2 flex-grow-1 bd-highlight">
                                            <input type="text" v-model="searchdata.name" disabled
                                                class="form-control form-control-theme" value="">
                                        </div>
                                    </div>
                                </div>
                                <!-- 领料单 -->
                                <div class="col-12">
                                    <div class="d-flex bd-highlight align-items-center">
                                        <div class="p-2 bd-highligh flex-shrink-0 filedlabel">{{lan['Picking_No']}}</div>
                                        <div class="p-2 flex-grow-1 bd-highlight">
                                            <input type="text" v-model="searchdata.PickingNumber" class="form-control form-control-theme" value="">
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class=" row justify-content-center mt-4">
                                <div class="col-4 col-md-4">
                                    <button type="button" onclick="loadData()" tapmode=""
                                        class="btn btn-primary btn-action">{{lan['OK']}}</button>
                                </div>


                                <div class="col-4 col-md-4">
                                    <button type="button" tapmode="" onclick="close_win()"
                                        class="btn btn-primary btn-action">{{lan['Cancel']}}</button>
                                </div>

                            </div>

                        </div>

                        <div class="modal-footer">
                            <div class="copyright">
                                <div class="row" :gutter="10">
                                    <div  class="col-5" style="text-align: right;">{{lan['Version']}}：</div>
                                    <div  class="col-7">{{appversion}}</div>
                                    <div  class="col-5"  style="text-align: right;">{{lan['Site']}}：</div>
                                    <div  class="col-7">{{SiteName}}</div>
                                    <div  class="col-5"  style="text-align: right;">{{lan['Company']}}：</div>
                                    <div  class="col-7">{{CompanyName}}</div>
                                </div>
                            </div>
                        </div>

                    </div>
                </div>
            </div>

        
            <div class="buysearch buysearch2">
                <div class="row   align-items-center">
                    <div class="col-12 col-sm-12 col-md-12">
                        <table class="table table-buy table-borderless table-sm">
                            <tr>
                                <td class="ttl">{{lan['Issue_Date']}}</td>
                                <td class="ttl">{{lan['Picking_No']}}</td>
                            </tr>
                            <tr>
                                <td> {{searchdata.ArrivedDate}}</td>
                                <td>{{searchdata.PickingNumber}}</td>
                            </tr>
                        </table>
                        
                    </div>
                </div>

            </div>

            <div class="row   align-items-center">
                <div class="col-12 col-sm-12 col-md-12">
                    <table class="table table-buy table-borderless table-sm">
                        <thead>
                            <tr>
                                <!-- /{{lan['Desc']}} -->
                                <th scope="col">{{lan['LineP']}}</th>
                                <th scope="col">{{lan['Part']}}</th>
                                <th scope="col">{{lan['Job_No']}}</th>
                                <th scope="col">{{lan['ReqDate']}}</th>
                                <th scope="col">{{lan['ASM']}}</th>
                                <th scope="col">{{lan['Delivered_Qty']}}</th>
                                <th scope="col"></th>  
                            </tr>
                            <tr>
                                <th scope="col"></th>
                                <th scope="col"></th>
                                <th scope="col"></th>
                                <th scope="col">{{lan['Require_Qty']}}</th>
                                <th scope="col">{{lan['Mtl']}}</th>
                                <th scope="col">{{lan['The_Qty']}}</th>
                                <th scope="col"></th>  
                            </tr>
                            
                        </thead>
                        <tbody>
                            
                        </tbody>
                    </table>
                    <div  v-for="(item,k) in goodlist" :key="k">
                        <table class="table table-buy table-borderless table-sm">
                            <tr>
                                <td>{{item.UD102A_ChildKey1}}</td>
                                <td>{{item.UD102A_ShortChar03}}</td>
                                <td>{{item.UD102A_ShortChar01}}</td>
                                <td>{{formatted_time(item.Calculated_DueDate)}}</td>
                                <td>{{processNumber(item.UD102A_Number05,item.NumOfDec)}}</td>
                                <td>{{processNumber(item.UD102A_Number03,item.NumOfDec)}}</td>
                                <td rowspan="2"><i v-if="!Lot_btn" @click="addPartChange(item,k)" class="iconfont icon-add"></i></td>
                            </tr>
                            <tr>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td>{{processNumber(item.UD102A_Number02,item.NumOfDec)}}{{item.IUM}}</td>
                                <td>{{processNumber(item.UD102A_Number07,item.NumOfDec)}}</td>
                                <td>{{processNumber(item.oldQty,item.NumOfDec)}}</td>
                            </tr>
                        </table>
                        <div class="d-flex bd-highlight align-items-center" v-if="goodlist[k].list.length > 0"  v-for="(item1,index1) in goodlist[k].list" :key="index1">
                            <div class="pt-2 flex-grow-1 bd-highlight">
                                <table class="table table-buy table-borderless table-sm">
                                    <tr>
                                        <td style="width: 45%;"  class="ttl">{{lan['WareHouseCode']}}</td>
                                        <td style="width: 45%;"  class="ttl"> {{lan['BinNum']}}</td>
                                    </tr>
                                    <tr>
                                        <td style="width: 45%;">
                                            <div class="wareContent">
                                                <input   v-if="!item1.warehouseFlag" type="text"
                                                :disabled = "Lot_btn"
                                                v-model="goodlist[k].list[index1].WareHouseCode"
                                                @click="warehouseFocus(item,k,item1,index1)"
                                                class="form-control form-control-num" value="">
                                                <select  v-if="item1.warehouseFlag" @change="binNumChange(item,k,item1,index1)" v-model="goodlist[k].list[index1].WareHouseCode" 
                                                    class="form-control"    :disabled = "Lot_btn" :class="[item1.warehouseFlag ? 'warhouseClass' + index1 : '']"   data-live-search="true">
                                                    <option v-for="(item2,index2) in item.WareHouseCodeList" :key="index2" 
                                                        :value="item2.Warehse_WarehouseCode" :data-name="item2.Warehse_WarehouseCode">
                                                        {{item2.Warehse_WarehouseCode}}</option>
                                                </select>
                                                <i v-if="!item1.warehouseFlag" style="margin-left: 5px;" @click="onWareQuery(item1,index1)" class="iconfont icon-scan"></i>
                                                <i v-if="item1.warehouseFlag" style="margin-left: 5px;" @click="onWareScan(item1,index1)" class="iconfont icon-query"></i>
                                            </div>
                                        </td>
                                        <td style="width: 45%;">
                                            <div class="wareContent">
                                                <input   v-if="!item1.binFlag" type="text"
                                                @click="binFocus(item,k,item1,index1)"
                                                :disabled = "Lot_btn"
                                                v-model="goodlist[k].list[index1].BinNum"
                                                class="form-control form-control-num" value="">
                                                <select v-if="item1.binFlag"   :disabled = "Lot_btn"  @change="numChange(item,k,item1,index1)"   v-model="goodlist[k].list[index1].BinNum" 
                                                    class="form-control" :class="[item1.binFlag ? 'binClass' + index1 : '']" data-live-search="true">
                                                    <option v-for="(item2,index2) in item1.BinNumList" :key="index2"  :value="item2.WhseBin_BinNum" >
                                                        {{item2.WhseBin_BinNum}}
                                                    </option>
                                                </select>
                                                <i  v-if="!item1.binFlag" style="margin-left: 5px;" @click="onBinQuery(item1,index1)" class="iconfont icon-scan"></i>
                                                <i  v-if="item1.binFlag" style="margin-left: 5px;" @click="onBinScan(item1,index1)" class="iconfont icon-query"></i>
                                            </div>
                                        </td>
                                    </tr>
                                </table>
                                <table class="table table-buy table-borderless table-sm">
                                    <tr>
                                        <td style="width: 30%;"class="ttl"> {{lan['Lot']}}</td>
                                        <td style="width: 30%;" class="ttl">{{lan['Qty']}}</td>
                                        <td style="width: 30%;" class="ttl"></td>
                     
                                    </tr>
                                    <tr>
                                        <td  style="width: 30%;">
                                            <div class="wareContent">
                                                <input  type="number"
                                                v-if="item1.lotFlag"
                                                @blur="lotBlur(item,k,item1,index1)"
                                                :disabled="!item.Part_TrackLots"
                                                v-model="item1.LotNum"
                                                class="form-control form-control-num" value="">
                                                <input  type="number"
                                                v-if="!item1.lotFlag"
                                                :disabled="!item.Part_TrackLots"
                                                @click="lotFocus(item,k,item1,index1)"
                                                v-model="item1.LotNum"
                                                class="form-control form-control-num" value="">
                                                <i  v-if="!item1.lotFlag" style="margin-left: 5px;" @click="onLotQuery(item1,index1)" class="iconfont  icon-scan"></i>
                                                <i  v-if="item1.lotFlag" style="margin-left: 5px;" @click="onLotScan(item1,index1)" class="iconfont icon-query"></i>
                                            </div>
                                        </td>
                                        <td  style="width: 30%;"> 
                                            <input  type="number"
                                            :disabled="Lot_btn"
                                            @input="checkDecimal(item,k,item1,index1)"
                                            @change="checkNum(item,k,item1,index1)" 
                                            :step="item.AllowDecimals ? 'any' : '1'"
                                            v-model="item1.OnhandQty"
                                            class="form-control form-control-num" value=""> 
                                        </td>
                                        <td style="width: 30%;">
                                            <button type="button" tapmode="" @click="toSerial(item,k,item1,index1)" :disabled="!item.Part_TrackSerialNum"
                                            :class=" item.Part_TrackSerialNum == false ? 'btn-secondary':'btn-primary'"
                                            class="btn   btn-block">{{lan['Serial_No']}} <span
                                            class="badge badge-light">{{item1.SerialNum.length}}</span>
                                            </button>
                                        </td>
                                    </tr>
                                </table>  
                            </div>
                            <div class="pt-2 bd-highligh">
                                <i v-if="!Lot_btn" @click="removePartChange(item,k,item1,index1)" class="iconfont icon-delete"></i> 
                            </div>
                        </div>
                     
                    </div>
                </div>
            </div>


        </div>

        <div style="height:100px;"></div>
        <div class="action-row">
            <div class="container">
                <div class=" row justify-content-center">
                    <div class="col-4 col-md-3">
                        <button type="button" tapmode="" :disabled="receipt_btn" onclick="checksubmit();"
                            class="btn btn-primary btn-action">{{lan['Confirm']}}</button>
                    </div>
                    <div class="col-4 col-md-3">
                        <button type="button" @click="resetSubmit" :disabled="!receipt_btn && !Lot_btn" tapmode=""
                            class="btn btn-primary btn-action">{{lan['Reset']}}
                        </button>
                    </div>
                    <div class="col-4 col-md-3">
                        <button type="button" tapmode="" @click="close_win1"
                            class="btn btn-primary btn-action">{{lan['Cancel']}}
                        </button>
                    </div>

                </div>

            </div>

        </div>
    </div>

</body>
<script type="text/javascript" src="../script/lang.js"></script>
<script type="text/javascript" src="../script/model.js"></script>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/vue.min.js"></script>
<script type="text/javascript" src="../script/jquery.min.js"></script>
<script type="text/javascript" src="../script/bootstrap.bundle.min.js"></script>
<script type="text/javascript" src="../script/bootstrap-select.min.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript">
    var postcount = 0;
    var returncount = 0;
    var postlist = [];
    var tagspostcount = 0;
    var tags = [];

    const app = new Vue({
        el: '#app',
        data: {
            list: [],
            lists:[],
            goodlist: [],
            packList:[],
            outList:[],
            oldlist:[],
            outinfo:"",
            goodkeys: {},
            screenwidth: document.body.clientWidth,
            vendors: [],
            requirenum: 0,
            scannum: 0,
            inOutData:{},
            currentData:{},
            rowNum:1,
            searchdata: {
                name: '',
                JobNum: '',//2468
                ArrivedDate: timenow(),
                AssemblySeq: '0',
                VendorName: '',
                PONum: '',
                PONum: '',
                PickingNumber:''
            },
            uinfo: {},
            lotinfo: {},
            PartNumTrackSerialNum: {},
            firstFocus: false,
            //postlist: [],
            //postlistids: [],
            create_btn: false,
            receipt_btn: true,
            print_btn: true,
            Lot_btn:false,
            confirm_btn:false,
            print_num: '',
        },
        mounted() {
            const that = this
            window.onresize = () => {
                return (() => {
                    that.screenwidth = document.body.clientWidth
                })()
            }
            this.showmodal();
            setTimeout(function () {
                $("#JobNum").focus();
            }, 500);


            //init_select();
        },
        onShow() {

        },
        methods: {
            checkDecimal(ite,k,item, index) {
                console.log(JSON.stringify(app.goodlist),111111)
                if(item.WarehouseCode == ""){
                    api.toast({
                        msg: lan['WareHouseCode_placeholder'],
                        location: 'middle'
                    });
                    item.OnhandQty=""
                    return;
                }
                if(item.BinNum == ""){
                    api.toast({
                        msg: lan['BinNum_placeholder'],
                        location: 'middle'
                    });
                    item.OnhandQty=""
                    return;
                }
                if(ite.Part_TrackLots && item.LotNum == ""){
                    api.toast({
                        msg: lan['LotNum_placeholder'],
                        location: 'middle'
                    });
                    item.OnhandQty=""
                    return;
                }
                    // 获取输入的值
                    let inputValue = item.OnhandQty;

                // 将输入值解析为浮点数
                let parsedValue = parseFloat(inputValue);

                // 如果解析成功，限制小数位数不超过 NumOfDec
                if (!isNaN(parsedValue)) {
                    const decimalCount = (inputValue.toString().split('.')[1] || "").length || 0;
                    if (decimalCount > item.NumOfDec) {
                    // 超过 NumOfDec 位小数，截取前 NumOfDec 位小数，不进行四舍五入
                    inputValue = inputValue.substring(0, inputValue.indexOf('.') + item.NumOfDec + 1);
                    }
                    item.OnhandQty = inputValue;
                    for(let item1 of app.goodlist) {
                        let totalOnhandQty = 0;
                        for(let item of item1.list) {
                            let onhandQty = parseFloat(item.OnhandQty);
                            totalOnhandQty += onhandQty;
                        }
                        item1.oldQty = totalOnhandQty;
                    }
                    if(item.OldQty != item.OnhandQty){
                        item.SerialNum = []
                    }
                    this.check_canclick()
                }
            },
            addPartChange(item,k){
                loadWarehouseCodeData(item,k);
            },
            resetSubmit(){
                this.receipt_btn = false;
                this.Lot_btn = false;
                loadData()
            },
            check_canclick: function () {
                var canclick = false;
                var tc = false;
                var sr = false;
                var tg = false;
                var sc = true;
                for (i in this.goodlist) {
                    for(let i1 in this.goodlist[i].list){
                        let item =this.goodlist[i].list[i1]
                        if(item.OnhandQty == ""){
                            tg = true;
                        }
                        if (this.goodlist[i].is_SerialNum == 1) {
                            console.log(this.receipt_btn,22222)
                            if (item.SerialNum.length == 0) {
                                sr = true;
                            }
                        }
                        if (this.goodlist[i].is_Lot == 1) {
                            if (!item.LotNum || item.LotNum == '') {
                                tc = true;
                            }
                        }

                    }
                    sc = false;

                }
            
                if (tc  || tg  || sc || sr) {
                    canclick = true;
                }

                this.receipt_btn = canclick;
                console.log(this.receipt_btn,11111)
            },
            lotFocus:function(item,index,item1,index1){
                if(item.WarehouseCode == ""){
                    api.toast({
                        msg: lan['WareHouseCode_placeholder'],
                        location: 'middle'
                    });
                    return;
                }
                if(item.BinNum == ""){
                    api.toast({
                        msg: lan['BinNum_placeholder'],
                        location: 'middle'
                    });
                    return;
                }
                setTimeout(function(){
                    scan3(item,index,item1,index1)
                },100)
            
            },
            lotBlur:function(item,index,item1,index1){
                if(item.WarehouseCode == ""){
                    api.toast({
                        msg: lan['WareHouseCode_placeholder'],
                        location: 'middle'
                    });
                    return;
                }
                if(item.BinNum == ""){
                    api.toast({
                        msg: lan['BinNum_placeholder'],
                        location: 'middle'
                    });
                    return;
                }
                loadPartNumStatus(item,index,item1,index1)
            },
            warehouseFocus:function(item,index,item1,index1){
                setTimeout(function(){
                    scan1(item,index,item1,index1)
                },100)
            },
            binFocus:function(item,index,item1,index1){
                if(item.WarehouseCode == ""){
                    api.toast({
                        msg: lan['WareHouseCode_placeholder'],
                        location: 'middle'
                    });
                    return;
                }
                setTimeout(function(){
                    scan2(item,index,item1,index1)
                },100)
            },
            removePartChange(item,index,item1,index1){
                if (this.goodlist[index].list && this.goodlist[index].list.length > 0) {
                    this.goodlist[index].list.splice(index1, 1);
                    data.RowNum = data.RowNum - 1
                }
            },
            toSerial: function (item, index,item1,index1) {
                if(!item1.OnhandQty){
                    api.toast({
                        msg: lan['Complete_Qty_placeholder'],
                        location: 'middle'
                    });
                    return;
                }
                var data = {};
                if(item1.OnhandQty != item1.OldQty){
                    item1.SerialNum = []
                }
                item1.PartNum = item.PartNum;
                item1.PartDescription = item.PartDescription;
                var InputOurQty = processNumber(item1.OnhandQty, item.NumOfDec);
               
                if(item1.SerialNum.length==0 ){
                    for (let i = 0; i < InputOurQty; i++) {
                        item1.SerialNum.push({
                            'type': i+1,
                            'SerialNumber': '',
                        })
                    }
                }
             
                data.post = item1;
                data.index = index;
                data.index1 = index1;
                data.post.snsCheck = app.snsCheck
                data.post.index = index;
                data.post.index1 = index1;
                data.post.Lot_btn = app.Lot_btn;
                data.searchdata = this.searchdata;
                data.title = lan['Picking_List'];
                data.frame = "sn_job_issue";
                data.right = [{
                    text: lan["Scan"],
                    color: '#fff',
                }];
                console_debug(data,"sn_job_issue");

                openNavWin2(data.frame, data);

            },
            binNumChange:function(item,index,item1,index1){
                   
                setTimeout(function(){
                    loadBinData(item,index,item1,index1)
                },100)
                      
            },
            onWareQuery(item,index){
                item.warehouseFlag = true;
                $('.warhouseClass' +index).val(item.WareHouseCode).trigger("change");
            },
            onWareScan(item,index){
                item.warehouseFlag = false;
            },
            onBinQuery(item,index){
                item.binFlag = true;
                $('.binClass' +index).val(item.BinNum).trigger("change");
            },
            onBinScan(item,index){
                item.binFlag = false;
            },
            onLotQuery(item,index){
                item.lotFlag = true;
            },
            onLotScan(item,index){
                item.lotFlag = false;
            },
            numChange:function(item,index,item1,index1){
                setTimeout(function(){
                    loadPartNumStatus(item,index,item1,index1)
                },100)
            },
            checkNum: function (item, index,item1,index1) {
                var g_OnhandQty = this.goodlist[index].list[index1].MaxQty;
                var OldQty = processNumber(this.goodlist[index].list[index1].OnhandQty,this.goodlist[index].NumOfDec);
                var OnhandQty =processNumber(this.goodlist[index].OnhandQty,this.goodlist[index].NumOfDec);
                // 计算 totalGOldQty，但不包括当前正在处理的对象
                let totalGOldQty = this.goodlist[index].list.reduce((total, good, currentIndex) => {
                    if (currentIndex !== index1) {
                        return total +  processNumber(good.OnhandQty,this.goodlist[index].NumOfDec);
                    }
                    return total;
                }, 0);            
                if (OldQty <= 0) {
                    OldQty = 1;

                }
                this.$set(this.goodlist[index].list[index1],"OnhandQty",OldQty)
            },
         
            showmodal: function () {
                if (this.screenwidth < 576) {
                    $('#exampleModal').modal('show');
                    //init_select();
                } else {

                    $('#JobNum').focus();
                }
            },
            hidemodal: function () {
                $('#exampleModal').modal('hide');
            },
        }
    });
    apiready = function () {
        api.parseTapmode();
        server = getapi();
        back_listen();
        app.vendors = get_prefs_data("Vendors");
        app.uinfo = get_user_info();
        userinfo = get_user_info();
        app.searchdata.name = userinfo.Name;
        api.addEventListener({
            name: 'infrared_scanning'
        }, function (ret, err) {
            $("input:focus").val(ret.value.str);
            app.searchdata.JobNum = $("#JobNum").val();
            if (ret && ret.value && ret.value.str && is_scan == 0) {
                loadqrData(ret.value.str);
            }

        });
      
        api.addEventListener({ name: 'navitembtn' }, function (ret, err) {
            if(ret.type == 'left'){
                if(app.confirm_btn){
                    close_win1()  
                }else{
                    close_win()
                }   
            }
            if (ret.type == 'right') { 
                scan()
            }
        });

        api.addEventListener({
            name: 'keyback',
            extra: {
                slidBackIntercept: true    
            }
        }, function (ret, err) {
            if(app.confirm_btn){
                close_win1()  
            }else{
                close_win()
            }   
        });

        api.addEventListener({
            name: 'sn_job_issue'
        }, function (ret, err) {
            if(ret && ret.value){
                var snposts = ret.value;
                console.log(JSON.stringify(snposts),33333)
                app.goodlist[snposts.index].list[snposts.index1].OnhandQty = snposts.OnhandQty;
                app.goodlist[snposts.index].list[snposts.index1].OldQty = snposts.OldQty;
                app.goodlist[snposts.index].list[snposts.index1].SerialNum = snposts.SerialNum;
                app.check_canclick()
                console.log(JSON.stringify(app.goodlist),44444)
                api.closeWin({name: 'sn_job_issue'});
            }
        });
    }
    function scan1(item,index,item1,index1){
        var FNScanner = api.require('FNScanner');
        FNScanner.open({
            autorotation: true
        }, function (ret, err) {
            console_debug(ret, err);
            if (ret) {
                if (ret.eventType == 'success') {
                    app.$set(app.$data.goodlist[index].list[index1],'WareHouseCode',ret.content)
                    setTimeout(function(){
                        loadBinData(item,index,item1,index1)
                    },300)
                }
            } 
        });
          
    }
    function scan2(item,index,item1,index1){
        var FNScanner = api.require('FNScanner');
        FNScanner.open({
            autorotation: true
        }, function (ret, err) {
            console_debug(ret, err);
            if (ret) {
                if (ret.eventType == 'success') {
                    app.$set(app.$data.goodlist[index].list[index1],'BinNum',ret.content)
                    setTimeout(function(){
                        loadPartNumStatus(item,index,item1,index1)
                    },300)
                }
            } 
        });
          
    }
    function scan3(item,index,item1,index1){
        var FNScanner = api.require('FNScanner');
        FNScanner.open({
            autorotation: true
        }, function (ret, err) {
            console_debug(ret, err);
            if (ret) {
                if (ret.eventType == 'success') {
                    app.$set(app.$data.goodlist[index].list[index1],'LotNum',ret.content)
                    setTimeout(function(){
                        loadPartNumStatus(item,index,item1,index1)
                    },300)
                }
            } 
        });
          
    }


    function scan() {

        var FNScanner = api.require('FNScanner');
        FNScanner.open({
            autorotation: true
        }, function (ret, err) {
            console_debug(ret, err);
            if (ret) {
                if (ret.eventType == 'success') {
                    app.searchdata.PickingNumber = ret.content
                }

            } else {
                //alert(JSON.stringify(err));
            }
        });
    }

    async function loadWarehouseCodeData(data,k) {
        userinfo = get_user_info();
        if (!userinfo.Token) {
            return;
        }
        $('.myselect3').selectpicker('destroy'); // 先销毁
        await api.ajax({
            url: server + 'BaqSvc/WMS_WarehouseForPart/?CompID=' + userinfo.Company + "&Site=" + userinfo.Site +"&PartNum="+data.PartNum,
            method: 'get',
            returnAll: false,
            headers: {
                'Authorization': userinfo.Token,
            },
            data: {}
        }, function (ret, err) {
            console.log(JSON.stringify(ret), 22222)
            if (ret && ret.value.length > 0) {
                app.$set(app.goodlist[k], 'WareHouseCodeList', ret.value);
                const item = itemdata({});
                app.goodlist[k].list.push(item);
                const bacth =localStorage.getItem('batch')
                console.log(JSON.stringify(app.goodlist),66666)
                if(bacth == 0){
                    firstOnhandData(app.goodlist[k],k,app.goodlist[k].list[data.RowNum-1],data.RowNum-1)
                    data.RowNum = data.RowNum + 1
                }
            }
        });
    }
   
    async function loadBinData(item,index,item1,index1) {
        userinfo = get_user_info();
        $('.myselect4').selectpicker('destroy'); // 先销毁
        await api.ajax({
            url: server + 'BaqSvc/WMS_WhseBin/?CompID=' + userinfo.Company + "&WarehouseCode=" + item1.WareHouseCode,
            method: 'get',
            returnAll: false,
            headers: {
                'Authorization': userinfo.Token,
            },
            data: {

            }
        }, function (ret, err) {
            if (ret && ret.value.length > 0) {
                app.$set(app.$data.goodlist[index].list[index1],'BinNumList',ret.value)
                setTimeout(function () {
                    app.check_canclick()
                }, 200)
            }

        });
    }
   
    function firstOnhandData(item,index,item1,index1){
        userinfo = get_user_info();
        var filter = "?CompID=" + userinfo.Company;
        filter += "&PartNum=" + item.PartNum;
        filter += "&RowNum=" + item.RowNum;
        console.log(JSON.stringify(filter),22222)
        api.ajax({
            url: server + 'BaqSvc/WMS_FirstLot/' + filter,
            method: 'get',
            returnAll: false,
            headers: {
                'Authorization': userinfo.Token,
            },
            data: {}  
        }, function (ret, err) {
            ajaxing = 0;
            is_scan = 0;
            console.log(JSON.stringify(ret),66666)
            hideProgress();
            if (ret && ret.value.length>0) {
                app.check_canclick()
                app.$set(app.$data.goodlist[index].list[index1],'MaxQty',processNumber(ret.value[0].PartBin_OnhandQty,item.NumOfDec)) 
                app.$set(app.$data.goodlist[index].list[index1],'LotNum',ret.value[0].PartBin_LotNum)
                app.$set(app.$data.goodlist[index].list[index1],'WareHouseCode',ret.value[0].PartBin_WarehouseCode)
                app.$set(app.$data.goodlist[index].list[index1],'BinNum',ret.value[0].PartBin_BinNum)
            }
        })
    }
    function loadPartNumStatus(item,index,item1,index1){
        userinfo = get_user_info();
        let filter = "?CompID=" + userinfo.Company;
        if (item.PartNum) {
            filter += "&PartNum=" + item.PartNum;
        }
        if(item1.WareHouseCode){
            filter += "&WhseCode=" + item1.WareHouseCode;
        }
        if(item1.BinNum){
            filter += "&Bin=" + item1.BinNum;
        }
        if(item1.LotNum){
            filter += "&LotNum=" + item1.LotNum;
        }
        api.ajax({
            url: server + 'BaqSvc/WMS_PartBinOnhand/' + filter,
            method: 'get',
            returnAll: false,
            headers: {
                'Authorization': userinfo.Token,
            },
            data: {} 
        },function(ret,err){
            console.log(filter,44444)
            console.log(JSON.stringify(ret),111111)
            console.log(JSON.stringify(err),222222)
            if(ret && ret.value.length>0){
                app.check_canclick()
                if(item.Part_TrackLots && item1.LotNum != ""){
                    app.$set(app.$data.goodlist[index].list[index1],'MaxQty',processNumber(ret.value[0].PartBin_OnhandQty,item.NumOfDec)) 
                }
                if(!item.Part_TrackLots){
                    app.$set(app.$data.goodlist[index].list[index1],'MaxQty',processNumber(ret.value[0].PartBin_OnhandQty,item.NumOfDec))   
                }    
            }
        })
    }   
    function itemdata(data){
        data.WareHouseCode='';
        data.BinNum='';
        data.MaxQty='';
        data.LotNum='';
        data.OnhandQty='';
        data.OldQty='';
        data.SerialNum=[];
        data.BinNumList = [];
        data.warehouseFlag=false;
        data.binFlag=false;
        data.lotFlag=false;

        return data
    }
   
    function revise_total(goodlist, list){
        console.log(JSON.stringify(list),333333)
        console.log(JSON.stringify(goodlist),22222)
        // 将list中的数据按照PartNum进行分组
        if(list.length > 0){
            // 重新计算 list 中的 TotalQty
            list.forEach((item) => {
                if (item.goods && item.goods.length > 0) {
                    item.TotalQty = item.goods.reduce((total, gItem) => processNumber(total,gItem.NumOfDec) + processNumber(gItem.g_OldQty,gItem.NumOfDec), 0);
                }
            });
            const listGroupedByPartNum = list.reduce((acc, item) => {
                if (!acc[item.PartNum]) {
                    acc[item.PartNum] = [];
                }
                acc[item.PartNum].push(item);
                return acc;
            }, {});

            // 计算goodlist中每个项目的UD102A_Number03值
            goodlist.forEach((good) => {
                const partNum = good.UD102A_ShortChar03;
                const childKey1 = good.UD102A_ChildKey1;
                
                if (listGroupedByPartNum[partNum]) {
                    const matchingItems = listGroupedByPartNum[partNum].filter((item) =>
                    item.goods.some((gItem) => gItem.g_RowLine === childKey1)
                    );
                    const sumGOldQty = matchingItems.reduce((total, item) => {
                    const matchingGood = item.goods.find((gItem) => gItem.g_RowLine === childKey1);
                    return total + processNumber(matchingGood.g_OldQty,matchingGood.NumOfDec);
                    },0);

                    good.oldQty = sumGOldQty;
                    good.oldQty = Math.min(good.oldQty, good.UD102A_Number02);
                  
                }else{
                    good.UD102A_Number03 = 0;
                    good.oldQty = 0
                }
            });
        }else{
            app.oldlist.forEach((good,index) => {
                if(good.UD102A_ChildKey1 == goodlist[index].UD102A_ChildKey1){
                    goodlist[index].UD102A_Number03 = good.UD102A_Number03;
                    goodlist[index].oldQty = good.oldQty;
                }
                
            })
            app.lists = []
            app.list = []
        }
       
    }
    function calc_total(goodlist, list) {
        console.log(JSON.stringify(goodlist),33333)
        console.log(JSON.stringify(list),44444)
        const goodCountMap = {};

        function distributeOnhandQty(onhandQty, goods) {
            for (let i = 0; i < goods.length; i++) {
                const g_OnhandQty = goods[i].g_OnhandQty;
                const g_OldQty = goods[i].g_OldQty;
                if(g_OldQty == 0){
                    if (onhandQty >= g_OnhandQty) {
                        if(goods[i].g_OldQty != 0){
                            goods[i].g_OldQty = processNumber(goods[i].g_OldQty + (g_OnhandQty - goods[i].g_OldQty),goods[i].NumOfDec);  
                        }else{
                            goods[i].g_OldQty =processNumber(g_OnhandQty,goods[i].NumOfDec)
                        }
                        onhandQty -= g_OnhandQty;
                    } else {
                        goods[i].g_OldQty =processNumber(onhandQty,goods[i].NumOfDec);
                        onhandQty = 0;
                        break;
                    }
                }
               
            }
            return onhandQty;
        }


        function processList(index) {
            if (index >= list.length) {
                return;
            }

            const currentItem = list[index];
            const goods = currentItem.goods;

            if (currentItem.OnhandQty <= goods[0].g_OnhandQty && goods[0].g_OldQty == 0) {
                console.log(currentItem.OnhandQty,333333)
                goods[0].g_OldQty = currentItem.OnhandQty;
            } else if (currentItem.OnhandQty > goods.reduce((total, gItem) => total + gItem.g_OnhandQty, 0) && (currentItem.TotalQty && currentItem.TotalQty == 0)) {
                console.log(currentItem.OnhandQty,444444)
                distributeOnhandQty(currentItem.OnhandQty, goods);
            } else if(currentItem.TotalQty && currentItem.TotalQty == 0) {
                console.log(currentItem.OnhandQty,555555)
                distributeOnhandQty(currentItem.OnhandQty, goods);
            }else{
                console.log(currentItem.OnhandQty,66666)
                distributeOnhandQty(currentItem.OnhandQty, goods);
            }

            currentItem.goods = goods.filter((good) => good.g_OldQty !== 0);

            const key = currentItem.PartNum;
            goodCountMap[key] = goodCountMap[key] ? goodCountMap[key] + currentItem.OnhandQty : currentItem.OnhandQty;

            const nextIndex = index + 1;
            processList(nextIndex);
        }

        processList(0);
        // 重新计算 list 中的 TotalQty
        list.forEach((item) => {
            if (item.goods && item.goods.length > 0) {
                item.TotalQty = item.goods.reduce((total, gItem) => total + gItem.g_OldQty, 0);
                // 假设'list'数组的第一个元素是相关的数据
               if(item.is_SerialNum){
                    let serialNumArray = item.SerialNum;
                    let goodsArray = item.goods;

                    // 遍历goodsArray，分配对应数量的SerialNum
                    let currentIndex = 0;
                    for (let i = 0; i < goodsArray.length; i++) {
                        if(goodsArray[i].SerialNum.length == 0){
                            let oldQty = goodsArray[i].g_OldQty;
                            if (currentIndex + oldQty <= serialNumArray.length) {
                                goodsArray[i].SerialNum = serialNumArray.slice(currentIndex, currentIndex + oldQty);
                                currentIndex += oldQty;
                                goodsArray[i].is_SerialNum = item.is_SerialNum
                            } else {
                                // 若SerialNum数量不足，则截取剩余的全部SerialNum
                                goodsArray[i].is_SerialNum = item.is_SerialNum
                                goodsArray[i].SerialNum = serialNumArray.slice(currentIndex);
                                break;
                            }
                        }
                    }

               }
               
            }
        });

       // 将list中的数据按照PartNum进行分组
       const listGroupedByPartNum = list.reduce((acc, item) => {
            if (!acc[item.PartNum]) {
                acc[item.PartNum] = [];
            }
            acc[item.PartNum].push(item);
            return acc;
        }, {});

        // 计算goodlist中每个项目的UD101A_Number10值
        goodlist.forEach((good) => {
            console.log(JSON.stringify(goodlist),66666)
            console.log(JSON.stringify(good),77777)
            const partNum = good.UD102A_ShortChar03;
            const childKey1 = good.UD102A_ChildKey1;
            console.log(partNum,33333)
            console.log(childKey1,44444)
            if (listGroupedByPartNum[partNum]) {
                const matchingItems = listGroupedByPartNum[partNum].filter((item) =>
                    item.goods.some((gItem) => gItem.g_RowLine === childKey1)
                );
                const sumGOldQty = matchingItems.reduce((total, item) => {
                const matchingGood = item.goods.find((gItem) => gItem.g_RowLine === childKey1);
                return total + processNumber(matchingGood.g_OldQty,matchingGood.NumOfDec);
                }, 0);
                console.log(sumGOldQty,55555)
                good.oldQty = sumGOldQty;
                good.oldQty = Math.min(good.oldQty, good.UD102A_Number02);
            }
        });

        console.log(JSON.stringify(list),11111)
        console.log(JSON.stringify(goodlist),22222)
      
    }
    function loadData() {
        if(app.searchdata.PickingNumber == ''){
            api.toast({
                msg: lan['Store_Requisition_placeholder'],
                location: 'middle'
            });
            return;
        }else{
            userinfo = get_user_info();
        
            showProgress(lan['Loading']);

            api.ajax({
                url: server + 'BaqSvc/WMS_ARCOPickingList/?CompID='+ userinfo.Company +'&Site='+userinfo.Site+'&PickingNumber='+app.searchdata.PickingNumber,
                method: 'get',
                returnAll: false,
                headers: {
                    'Authorization': userinfo.Token,
                    'Content-Type': 'application/json;charset=utf-8'
                },
                data: {}
            }, function (ret, err) {
                ajaxing = 0;
                console_debug(ret, err);
                hideProgress();
                console.log(JSON.stringify(ret.value),99999)
                if (ret && ret.value.length > 0) {
                    var newlist = init_list(ret.value);

                    if (newlist.length == 0) {
                        api.toast({
                            msg: "no data!",
                            location: 'middle'
                        });
                        return;
                    }
                    app.goodlist = [];
                    app.requirenum = 0;
                    app.oldlist = app.oldlist.concat(JSON.parse(JSON.stringify(newlist)));
                    app.goodlist = app.goodlist.concat(newlist);
                    app.goodlist = app.goodlist.sort((a, b) => {
                        // 首先对创建时间进行比较
                        if (new Date(a.Calculated_DueDate).getTime() < new Date(b.Calculated_DueDate).getTime()) return -1;
                        if (new Date(a.Calculated_DueDate).getTime() > new Date(b.Calculated_DueDate).getTime()) return 1;
                        
                        // 其次对工单号进行比较
                        if (new Date(a.Calculated_DueDate).getTime() === new Date(b.Calculated_DueDate).getTime()) {
                            if (parseInt(a.UD102A_ShortChar01) < parseInt(b.UD102A_ShortChar01)) return -1;
                            if (parseInt(a.UD102A_ShortChar01) > parseInt(b.UD102A_ShortChar01)) return 1;
                        }
                        
                        // 然后对半成品号进行比较
                        if (new Date(a.Calculated_DueDate).getTime() === new Date(b.Calculated_DueDate).getTime() && parseInt(a.UD102A_ShortChar01) === parseInt(b.UD102A_ShortChar01)) {
                            if (parseInt(a.UD102A_Number05) < parseInt(b.UD102A_Number05)) return -1;
                            if (parseInt(a.UD102A_Number05) > parseInt(b.UD102A_Number05)) return 1;
                        }
                        
                        // 最后对物料序号进行比较
                        if (new Date(a.Calculated_DueDate).getTime() === new Date(b.Calculated_DueDate).getTime() && parseInt(a.UD102A_ShortChar01) === parseInt(b.UD102A_ShortChar01) && parseInt(a.UD102A_Number05) === parseInt(b.UD102A_Number05)) {
                            if (parseInt(a.UD102A_Number07) < parseInt(b.UD102A_Number07)) return -1;
                            if (parseInt(a.UD102A_Number07) > parseInt(b.UD102A_Number07)) return 1;
                        }
                        
                        return 0; // 所有条件都符合返回0
                    });

                    for (i in app.goodlist) {
                        var key = app.goodlist[i].UD102A_ShortChar03 + "" + app.goodlist[i].UD102A_ChildKey1
    
                        if (!app.goodkeys[key]) {
                            app.goodkeys[key] = i;
                        } 
                        app.requirenum += processNumber(app.goodlist[i].UD102A_Number02,app.goodlist[i].NumOfDec);
                    }
                    console.log(JSON.stringify(app.goodlist),2222222)
                    console_debug(app.goodkeys, 'goodkeys');
                    app.confirm_btn = true
                    $('#exampleModal').modal('hide');

                } else {
                    api.toast({
                        msg: "no data!",
                        location: 'middle'
                    });
                }

            });
        }
    }
    //关闭取消事件
    function close_win1() {
        if(app.confirm_btn){
            api.confirm({
                title: lan['Tips'],
                msg: lan['issue_cancel_tips'],
                buttons: [lan['NO'], lan['YES'], lan['Cancel']]
            }, function (ret, err) {
                var index = ret.buttonIndex;
                if (index == 2) {
                    submitfrom();
                } else if (index == 1) {
                    close_win();
                }
            });
        }else{
            close_win();
        }

    }

    //JobMtl
    function init_list(data) {
        var ret = [];
        for (i in data) {
            data[i].PartNum = data[i].UD102A_ShortChar03;
            data[i].PartDescription = data[i].Part_PartDescription;
            data[i].NumOfDec = data[i].UOM_NumOfDec;
            data[i].IUM = data[i].UD102A_ShortChar04
            data[i].WareHouseCodeList = [];
            data[i].oldQty = 0
            data[i].OnhandQty = processNumber(data[i].UD102A_Number02,data[i].UOM_NumOfDec)-processNumber(data[i].UD102A_Number03,data[i].UOM_NumOfDec);
            data[i].is_Lot = -1; //批号判断 -1 未查询  1 需创建 2 不需创建
            data[i].is_SerialNum = -1; //序列号判断 -1 未查询  1 需创建 2 不需创建
            if (data[i].Part_TrackLots) {
                data[i].is_Lot = 1
            } else {
                data[i].is_Lot = 2
            }
            if (data[i].Part_TrackSerialNum) {
                data[i].is_SerialNum = 1; 
            } else {
                data[i].is_SerialNum = 2; 
            }
            data[i].list = [];
            data[i].RowNum = 1;
            data[i].TotalQty = processNumber(data[i].UD102A_Number02,data[i].UOM_NumOfDec);
            data[i].IssuedQty = processNumber(data[i].UD102A_Number03,data[i].UOM_NumOfDec);
            ret.push(data[i]);
        }
        return ret;
    }
    function loadqrData(data) {

        userinfo = get_user_info();
        var filter = "a.Company eq '" + userinfo.Company + "'";

        if (data.indexOf("TR") != -1) {
            filter += " and a.PackageID eq '" + data + "'";
        } else {
            filter += " and a.LabelNum eq '" + data + "'";
        }



        console_debug(filter, 'filter');
        // alert(filter)
        is_scan = 1;

        api.ajax({
            url: wmsserver + 'packagestatuswithtrantype/?filter=' + filter,
            method: 'get',
            returnAll: false,
            headers: {
                'token': wmstoken,
                'Content-Type': 'application/json;charset=utf-8'
            },
            data: {}
        }, function (ret, err) {
            ajaxing = 0;
            is_scan = 0;
            console_debug(ret, err);

            if (ret && ret[0]) {
                console.log(JSON.stringify(ret[0]),44443333)
                ret = Upper_arr(ret);
                loadCountryCode(ret).then(function(){
                    app.rowNum = app.rowNum + 1
                    for (i in ret) {
                        var ret1 = [];
                        ret1.push(ret[i]);
                        var res = check_repeat(ret1[0]);
                        if (res == 1) {
                            api.toast({
                                msg: lan['Carton_Label_exists'],
                                location: 'middle'
                            });
                            continue;
                        }
                        var res1 = check_wuliao(ret1[0]);
                        if (res1 == 0) {
                            api.toast({
                                msg: lan['not_in_issue'],
                                location: 'middle'
                            });
                            continue;
                        }
                       //检验阻断提示
                        if (!InspectBlocking(ret)) {
                            return; 
                        }
                        console.log(JSON.stringify(ret1),6666)
                        var newlist = get_qrnum(ret1);
                        console.log(JSON.stringify(newlist),7777)
                        console_debug(newlist, '');
                        if (newlist[0].OnhandQty == 0) {
                            api.toast({
                                msg: lan['Reached_quantity'],
                                location: 'middle'
                            });
                            continue;
                        }
                        app.lotinfo[ret1[0].PartNum] = ret1[0].LotNum;
                        //alert(newlist[0].is_SerialNum);
                        getSerialNum(ret1)

                    }

                })
                

            }else{
                hideProgress();
            }

        });
    }
    function loadPackageStatus(data){
        userinfo = get_user_info();
        app.currentData={}
        var filter = "Company eq '" + userinfo.Company + "'";

        if (data.indexOf("TR") != -1) {
            filter += " and PackageID eq '" + data + "'";
        } else {
            filter += " and LabelNum eq '" + data + "'";
        }
        // alert(filter)
        api.ajax({
            url: wmsserver + 'packagestatus/?filter=' + filter,
            method: 'get',
            returnAll: false,
            headers: {
                'token': wmstoken,
                'Content-Type': 'application/json;charset=utf-8'
            },
            data: {}
        },function(ret,err){
            app.currentData = ret[0]
            console.log(JSON.stringify(ret),66666)
            if(ret && ret.length>0){
                let outRet = ret[0]
                if(outRet.lotNum == ""){
                    loadqrData(data)
                }else{
                    inoutData(outRet,data) 
                }
                
            }
        })
    }
    function inoutData(outRet,datas){
        console.log(JSON.stringify(outRet),3333)
        console.log(JSON.stringify(app.rowNum),4444)
        api.ajax({
            // url: wmsserver + 'packagestatus/?filter=' + filters,
            url: wmsserver + 'packagestatuslotcreatedate/?company=' + userinfo.Company + "&partnum=" + outRet.partNum +"&rownum="+ app.rowNum,
            method: 'get',
            returnAll: false,
            headers: {
                'token': wmstoken,
                'Content-Type': 'application/json;charset=utf-8'
            },
            data: {}
        }, function(ret, err){
            console.log(JSON.stringify(ret),1111)
            console.log(JSON.stringify(err),2222)
            if(ret && ret.length > 0){
                let outList = ret.filter(option => option.onhandQty !== 0);
                const bacth =localStorage.getItem('batch')
                let createDate = new Date(outRet.createDate)
                let createDate1 =new Date(outList[0].createDate)
                if(bacth == 0){
                    if(createDate.getTime() > createDate1.getTime()){

                        app.inOutData = outList[0];
                        $('#inoutModal').modal('show')

                    }else{
                        loadqrData(datas)
                    }
                }else{
                    loadqrData(datas)
                }
            
            }
            
        })
    }
    function get_goods(ret){
        console.log(JSON.stringify(ret),99999)
        console.log(JSON.stringify(app.packList),88888)
        ret.forEach(item => {
            app.packList.forEach(good => {
                if (item.PartNum === good.UD102A_ShortChar03 && processNumber(good.UD102A_Number02,good.NumOfDec) != processNumber(good.UD102A_Number03,good.NumOfDec)) {
                    item.goods.push({
                        g_OnhandQty:good.UD102A_Number03 != 0 ? processNumber(good.UD102A_Number02,good.NumOfDec)-processNumber(good.UD102A_Number03,good.NumOfDec):processNumber(good.UD102A_Number02-good.oldQty,good.NumOfDec),
                        g_OldQty: 0,
                        g_RightQty:processNumber(good.UD101A_Number10,good.NumOfDec),
                        g_PartNum:good.UD102A_ShortChar03,
                        g_RowLine:good.UD102A_ChildKey1,	
                        LabelNum:item.LabelNum,
                        PartNum:good.UD102A_ShortChar03,
                        Description:item.PartDescription,
                        JobNum:parseInt(good.UD102A_ShortChar01),
                        is_SerialNum:item.is_SerialNum,
                        NumOfDec:item.NumOfDec,
                        SerialNum:[],
                    });
                }
            });
        });

    }


    function getRowkey(PartNum) {
        var key = "";
        for (i in app.goodlist) {
            var IssuedQty = processNumber(app.goodlist[i].UD102A_Number03,app.goodlist[i].NumOfDec);
            var SellingReqQty = processNumber(app.goodlist[i].UD102A_Number02,app.goodlist[i].NumOfDec);
            if (app.goodlist[i].UD102A_ShortChar03 == PartNum && IssuedQty < SellingReqQty) {
                key = app.goodlist[i].UD102A_ShortChar03  + "" + app.goodlist[i].UD102A_ChildKey1;
                break;
            }
        }
        return key;

    }


   
    function check_wuliao(data) {
        var res = 0;
        for (i in app.goodlist) {
            console_debug(data.PartNum, app.goodlist[i].PartNum);
            if (data.PartNum == app.goodlist[i].UD102A_ShortChar03) {
                res = 1;
            }
        }
        //alert(res);
        return res;
    }
    function check_repeat(data) {
        var res = 0;
        for (i in app.lists) {
            if (data.LabelNum == app.lists[i].LabelNum) {
                res = 1;
            }
        }
        return res;
    }




    function getvendorName(ob) {
        console_debug(app.searchdata);
        var vname = $('#vendorselect option:selected').attr("data-name");
        app.searchdata.VendorName = vname;
    }

    function setList(lists) {
        const mergedList = [];

        for (const item of lists) {
            const mergedItem = {
            ...item,
            OnhandQty: 0,
            SerialNum: [],
            };

            for (const listItem of lists) {
            if (
                listItem.LabelNum === item.LabelNum &&
                listItem.PartNum === item.PartNum &&
                listItem.goods[0].g_RowLine === item.goods[0].g_RowLine
            ) {
                mergedItem.OnhandQty += listItem.goods[0].g_OldQty; // 累加 g_OldQty

                if (listItem.goods[0].SerialNum && listItem.goods[0].SerialNum.length > 0) {
                mergedItem.SerialNum.push(...listItem.goods[0].SerialNum); // 合并 SerialNum
                }
            }
            }
            
            delete mergedItem.goods; // 删除 goods 字段
            mergedList.push(mergedItem); // 将合并后的记录加入 mergedList
        }

        return mergedList;
    }
    function checksubmit() {
        let hasNegativeQty = false;

        for (let i = 0; i < app.goodlist.length; i++) {
            const item = app.goodlist[i];
            if (
            item.shoucai === 2 &&
            item.PartClass_NegQtyAction === "Stop" &&
            item.list.length > 0
            ) {
            for (let j = 0; j < item.list.length; j++) {
                const listItem = item.list[j];
                if (processNumber(listItem.OnhandQty,item.NumOfDec) > processNumber(listItem.MaxQty,item.NumOfDec)) {
                    const message = `Order: ${item.OrderRel_OrderNum}, Line: ${item.OrderRel_OrderLine}. Part: ${item.PartNum}. Warehouse: ${listItem.WareHouseCode}. Bin: ${listItem.BinNum}. This transaction will result in a negative onhand quantity for the bin.`;
                    api.confirm({
                        title: lan["Tips"],
                        msg: message,
                        buttons: ["", lan["YES"]],
                    },function (ret, err) {
                        // 用户点击了 "YES"，继续提交数据或执行相应的操作
                        // 在这里编写用户点击 "YES" 后的处理逻辑
                        });
                    hasNegativeQty = true;
                    break; // 提示一次后停止继续检查
                }
            }
            }
        }

        if (!hasNegativeQty) {
            for (let i = 0; i < app.goodlist.length; i++) {
                const item = app.goodlist[i];
                if (item.shoucai === 2 && item.PartClass_NegQtyAction === "Warn" && item.list.length > 0) {
                    for (let j = 0; j < item.list.length; j++) {
                        const listItem = item.list[j];
                        if (processNumber(listItem.OnhandQty,item.NumOfDec) > processNumber(listItem.MaxQty,item.NumOfDec)) {
                            const message = `This transaction will result in a negative onhand quantity for Part: ${item.PartNum}, Bin: ${listItem.BinNum}. Do you want to continue?`;
                            api.confirm(
                            {
                                title: lan["Tips"],
                                msg: message,
                                buttons: [lan["NO"], lan["YES"], lan["Cancel"]],
                            },
                            function (ret, err) {
                                var index = ret.buttonIndex;
                                if (index === 2) {
                                    submitfrom();
                                    // 用户点击了 "YES"，继续提交数据或执行相应的操作
                                    // 在这里编写用户点击 "YES" 后的处理逻辑
                                } else if (index === 1) {
                                    close_win();
                                    // 用户点击了 "NO"，返回原页面或执行相应的操作
                                    // 在这里编写用户点击 "NO" 后的处理逻辑
                                }
                            }
                            );
                            return; // 提示一次后停止继续检查
                        }
                    }
                }
            }

            submitfrom();
        }
    }



    function submitfrom() {
        postlist = [];
        returncount = 0;
        postcount = 0;
        for (i in app.goodlist) {
            var item = app.goodlist[i];
            console.log(JSON.stringify(item),55555)
            if(item.list.length != 0){
                for(i1 in item.list){
                    let item1 = item.list[i1]
                    var row = {
                        "CompanyID": userinfo.Company,
                        "PlantID": userinfo.Site,
                        "UserName": userinfo.Name,
                        "Password": userinfo.password,
                        "TranDate": app.searchdata.ArrivedDate,
                        "PartNum": item.PartNum,
                        "UM": item.IUM,
                        "WarehouseCode": item1.WareHouseCode,
                        "BinNum": item1.BinNum,
                        "TranQty":item1.OnhandQty,
                        "JobNum": item.UD102A_ShortChar01,
                        "AssemblySeq": parseInt(item.UD102A_Number05),
                        "JobSeq": parseInt(item.UD102A_Number07),
                        "LotNum": item1.LotNum,
                        "UD102A_Key1":item.UD102A_Key1,
                        "UD102A_ChildKey1":item.UD102A_ChildKey1
                    }
                    var arr = [];
                    if(item1.SerialNum){
                        if(item1.SerialNum.length>0){
                            var SerialNum = item1.SerialNum;
                            for(k in SerialNum){
                                var row1 = {};
                                row1.SerialNumber = SerialNum[k].SerialNumber;
                                arr.push(row1);
                                
                            }
                        }
                    }
                
                    if(arr.length>0){
                        row.SelectedSerialNumbers = arr;
                    }
                    postlist.push(row);
                }
            }
           
        }
        console.log(JSON.stringify(row),3333333)
        if (!postlist) {
            api.toast({
                msg: lan['No_Data_Submit'],
                location: 'middle'
            });
            return;
        }
        console.log(JSON.stringify(postlist),4444)
        var datalist = {};
        for (i in postlist) {
            var item = postlist[i]
            var key = item.PartNum + item.JobSeq + item.WareHouseCode + item.BinNum + item.LotNum + item.AssemblySeq + item.UD102A_ChildKey1;
            if (datalist[key]) {
                datalist[key].TranQty = datalist[key].TranQty + item.TranQty;
                if (datalist[key].SelectedSerialNumbers) {
                    datalist[key].SelectedSerialNumbers = datalist[key].SelectedSerialNumbers.concat(item.SelectedSerialNumbers);
                } else {
                    datalist[key].SelectedSerialNumbers = item.SelectedSerialNumbers;
                }
            } else {
                datalist[key] = item;
            }
        }
        var postrows = [];
        for (key in datalist) {
            postrows.push(datalist[key]);
        }

        postcount = postrows.length;
        console.log(JSON.stringify(postrows),4444444)
        if (ajaxing) { return; } showProgress(lan['Loading']);
        // return
        for (i in postrows) {
            submit_issuemtl(postrows[i]);
        }




    }

    function submit_issuemtl(data1) {
        api.ajax({
            url: wmsserver + 'issuemtl/',
            method: 'post',
            returnAll: false,
            headers: {
                'token': wmstoken,
                'Content-Type': 'application/json;charset=utf-8'
            },
            //dataType: 'text',
            data: {
                body: create_submit_data(data1)
            }
            //data: {values: data1}
        }, function (ret, err) {
            ajaxing = 0;
            console_debug(ret, err);

            if (ret && ret.code == 1) {
                returncount++;
                if (returncount == postcount) {
                    api.alert({
                        title: lan['Tips'],
                        msg: lan['Submitted_successfully']
                    }, function (ret, err) {
                        app.receipt_btn = true
                        for(let i in app.goodlist){
                         app.goodlist[i].RowNum = 1
                        }
                        app.Lot_btn = true
                    });

                    hideProgress();
                    app.rowNum = 1
                }
            } else {
                app.receipt_btn = true
                hideProgress();
                errMassage(ret.msg)
            }

        });

    }


  
    function changeData(data) {
        var post = get_model();
        for (key in post) {
            if (data.hasOwnProperty(key)) {
                post[key] = data[key];
            }
        }
        console_debug(post, '');
        return post;
    }

</script>

</html>